

<template>
   
   <div>

      <div class='flex-row' style="margin: 1rem; color: #7b7b7b; font-size: 1rem;">
        <div class='flex-grow-1'>累计金额</div>
        <div class='flex-grow-0'>{{sum_money}}元</div>
      </div>

      <div style="width: 100%; height: 0.6rem; background-color: #e4e4e5; border-top:1px #cfcfcf solid; margin-top: 0.8rem;"></div>
    
    <div v-if="newList.length != 0">
    	<scroller lock-x   @on-scroll-bottom="onScrollBottom" ref="scrollerBottom" :scroll-bottom-offst="0" >
			
			<div >
	 
			     <div style="" v-for="(item,index) in newList">
			     	<group>
			
				        <cell :title="item.childnickname" >
				            <img slot="icon" width="40rem" height="40rem"style="display:block;margin-right:0.7rem;border-radius:20rem" :src="item.childavatar">
				            <div style="color: #ffb553; font-size:0.9rem">
				            	<!--<span class="iconfont icon-coin" style="margin-right: 0;"></span>-->
				            	<span>￥{{item.money}}</span>
				            </div>
				            <div style="color: #7b7b7b;font-size:0.8rem">{{item.addtime}}</div>
				            
				        </cell>
				
				     </group>
				     
				    <div v-show="item.status == 1" style="border-bottom: solid 1px #CBCBCB;"></div>
				     
				    <div v-show="item.status == 2" style="line-height: 1.8rem;border-bottom: solid 1px #CBCBCB;"> 
				    	<div style="padding-left: 15px;">状态：锁定</div>
				    	<div style="padding-left: 15px;">
				    		<span>原因：当前奖励非最大化</span>
				    		<span class="iconfont icon-right"></span>
				    	</div>
				    	<div style="padding-left: 15px;">{{item.time}}自动发放</div>
				    	
				    </div>
				    
				    <div v-show="item.status == 2" style="padding: 10px;" >
				    	<flexbox>
					      <flexbox-item><div class="flex-demo" style="text-align: right;">
					      	<button @click="toUpgrade" style="border: none;background: #FF9913;color: #FFFFFF;width: 5rem;height: 1.6rem;border-radius: 0.2rem;">升级会员</button>
					      </div></flexbox-item>
					      <flexbox-item><div class="flex-demo" style="text-align: left;">
					      	<button @click="toReceive(index)" style="background: #888888;border: none;color: #FFFFFF;width: 5rem;height: 1.6rem;border-radius: 0.2rem;">立即领取</button>
					      </div></flexbox-item>
					    </flexbox>
				    </div>
			     
			        <confirm v-model="show" :value="show"
			          title="提示"
			          @on-cancel="onCancel"
			          @on-confirm="onConfirm"> <p style="text-align:center;">您升级之后，可以领取更多奖励！</p>
			         </confirm> 
			     
			     </div>
	            
	            <load-more tip="loading" v-if="loading"></load-more>
				
			</div>
		
	    </scroller>
    	
    </div>
     
    
    <div v-if="newList.length == 0" style="margin: 1rem auto; width: 50%; text-align: center; color:#7b7a7a ">暂无更多内容！</div>  

   </div>
  
</template>

<script>

import  {base64, Confirm ,DatetimeView,PopupPicker,XButton,Scroller,LoadMore} from 'vux'



export default {

  components: {
    Confirm,PopupPicker,XButton,DatetimeView,Scroller,LoadMore,base64
  },
  data () {
    return {
    	
    	id:'',
    	show:false,
    	sum_integral:'',
    	list:'',
    	access_token:'',
    	sum_money:'',
    	
    	onFetching: false,
        loading:false,
        newList:[],
        page:1
	    
    }
  },
  methods:{
     
		    //获取详情
		    getDetail(){
		    	
		    	this.$store.commit('updateLoadingStatus',true);
		    	
		    	this.$http.get(this.$store.state.api + 'userdd/money-detail&access_token=' + this.access_token + '&page=' + 1)
			    .then((response) => {
			    		
			    console.log(response)
					
				if(response.body.code == 0) {
					
					this.list = response.body.data.list,
					this.sum_money = response.body.sum_money
					
					for(var i = 0 ; i < response.body.data.list.length ; i ++){
						
						this.newList.push(this.list[i])
						
					}
					
				} else {
					
				}
						
					
				this.$store.commit('updateLoadingStatus',false);		
					
				}, (response) => {
		             
		             
				});
		    },
    
            //触底加载
		    onScrollBottom:function(){
		      
		      if (this.onFetching) {
		        // do nothing
		      } else {
		        
		        
		        
		        console.log('开始')
		        
		        this.page = this.page + 1;
		        
		        console.log(this.page)
		        
		        this.getDetail();
		        
		        this.loading = true;
		        
		        
		        
		      this.onFetching = false
		        setTimeout(() => {
		
		
//		        this.info = this.info.concat(this.info);
		        this.onFetching = false
		          console.log('结束')
		          this.loading = false;
		        }, 500)
		        
		      }
		    },
	    
	    
    //跳转到会员
    toUpgrade(){
    	
    	this.$router.push({ path: '/upgrade'});
    	
    },
    
    //领取学分
    toReceive(index){
    	
    	this.show = true 
    	
    	console.log(index)
    	
    	this.id = this.newList[index].id
    	
    	console.log(this.id)
    	
    },
    
    //弹窗取消
    onCancel(){
       console.log('取消');
    },
    
    //弹窗确定
    onConfirm(){
       console.log('确定');
       
       this.$http.post(this.$store.state.api + 'userdd/take-integral/',
       {
       	access_token:'eQwkG6ssOApTuj7AcEmoXrwJjUiDWnKQ',
       	id:this.id
       })
	    .then((response) => {
	    		
	    console.log(response)
			
			if(response.body.code == 0) {
				
				
				
			} else {
				
			}
				
			
				
			
		}, (response) => {
             
             
		});
       
       
    },
    
     //获取地址栏信息
		getUrlStr(name){
	      let reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)","i");
	      if(reg.test(window.location.href)){
	        return unescape(RegExp.$2.replace(/\+/g," "))
	      }
	      return undefined
	    },	
    
          
    
  },
  
  mounted() {
  	
  	var access_token = this.getUrlStr('access_token');
           var parentId = this.getUrlStr('parent_id');
           
            if(parentId == undefined){
              parentId = 0;
           }
           
           var uid = this.getUrlStr('uid');
           
           if(parentId.toString().indexOf('?') > 0){
           	 parentId = parentId.split('?')[0];
           }
           
           var locurl = location.href;
           locurl = base64.encode(locurl.split('?')[0]);
           
       
           if(access_token != undefined){
         
              localStorage.setItem("access_token",access_token); 
              localStorage.setItem("parent_id",this.getUrlStr('uid'));


           }
           
            if(localStorage.getItem('access_token') != null){
         
              this.$root.registerjudge();
              this.$root.getShare();
              
            }else{
            	
        	  this.$root.gotoWechat(locurl,parentId);
            }
           
    	   this.access_token = localStorage.getItem('access_token');

    this.getDetail();

  }


}


</script>


<style>

  .weui-cells:after{
  	border-bottom: none !important;
  }
  
 


</style>
